/**
 * 设备管理初始化
 */
var Device = {
    id: "DeviceTable",
    seItem: null,
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Device.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'MAC地址', field: 'mac', visible: true, align: 'center', valign: 'middle'},
        {title: 'IP地址', field: 'ipAddress', visible: true, align: 'center', valign: 'middle'},
        // {title: '子网掩码', field: 'netMask', visible: true, align: 'center', valign: 'middle'},
        // {title: '网关', field: 'gateipAddress', visible: true, align: 'center', valign: 'middle'},
        {title: '序列号', field: 'serisalNumber', visible: true, align: 'center', valign: 'middle'},
        {title: '设备类型', field: 'deviceType', visible: true, align: 'center', valign: 'middle'},
        {title: '已添加', field: 'ynAddName', visible: true, align: 'center', valign: 'middle'},
        // {title: '连接模式', field: 'communicationName', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Device.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Device.seItem = selected[0];
        return true;
    }
};

/**
 * 打开查看门信息详情
 */
Device.openDeviceDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '系统参数详情',
            area: ['85%', '85%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/door/device/mgr/edit?ipAddress='+ Device.seItem.ipAddress+'&netMask=' + Device.seItem.netMask+'&gateipAddress' + Device.seItem.gateipAddress
        });
        this.layerIndex = index;
    }
};

/**
 * 点击添加设备信息表
 */
Device.openAddEquipmentInfo = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '添加设备信息表',
            area: ['85%', '85%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/door/EQUIPMENT/INFO/addOnSearch?ipAddress=' + Device.seItem.ipAddress + '&netMask=' + Device.seItem.netMask + '&gateipAddress' + Device.seItem.gateipAddress
        });
        this.layerIndex = index;
    }
};
/**
 * 查询门信息列表
 */
Device.search = function () {
    Device.table.refresh();
};

$(function () {
    var defaultColunms = Device.initColumn();
    var table = new BSTable(Device.id, "/door/device/mgr/list", defaultColunms);
    table.setPaginationType("client");
    Device.table = table.init();
});
